//
//  WCLoginViewController.m
//  WeChat
//
//  Created by lin on 15/7/16.
//  Copyright (c) 2015年 lin. All rights reserved.
//

#import "WCLoginViewController.h"
#import "WCRegisterViewController.h"
#import "WCNavigationController.h"
@interface WCLoginViewController() <WCRegisterViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end
@implementation WCLoginViewController
- (IBAction)loginBtnClick:(UIButton *)sender {
    WCUserInfo *userInfo = [WCUserInfo sharedWCUserInfo];
    userInfo.usr = self.userLabel.text;
    userInfo.pwd = self.pwdField.text;
    
    [super login];
    
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    //获取注册控制器，并设置代理,获得的是导航控制器
    id destVC = segue.destinationViewController;
    if ([destVC isKindOfClass:[WCNavigationController class]]) {
        WCNavigationController *nav = (WCNavigationController*)destVC;
        if ([nav.topViewController isKindOfClass:[WCRegisterViewController class]]) {
            WCRegisterViewController *registerVC = (WCRegisterViewController*)nav.topViewController;
            registerVC.delegate = self;
        }
      
    }
    
}
#pragma mark registerdelegate
-(void)registerViewControllerDidFinishRegister{
    //完成注册，显示label
    self.userLabel.text = [WCUserInfo sharedWCUserInfo].registerUsr;
    [MBProgressHUD showSuccess:@"请重新输入密码" toView:self.view];

}

-(void)viewDidLoad{
    [super viewDidLoad];
    self.pwdField.background = [UIImage stretchedImageWithName:@"operationbox_text"];
//    UIImageView *lockView = [[UIImageView alloc] init];
//    lockView.image = [UIImage imageNamed:@"Card_Lock"];
//    lockView.frame = CGRectMake(40, 0, 20, 20);
//    self.pwdField.leftView = lockView;
//    self.pwdField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Card_Lock"]];
    [self.pwdField addLeftViewWithImage:@"Card_Lock"];
    
    self.pwdField.leftViewMode = UITextFieldViewModeAlways;
    [self.loginBtn setResizeN_BG:@"fts_green_btn" H_BG:@"fts_green_btn_HL"];
    NSString *usr = [WCUserInfo sharedWCUserInfo].usr;
    self.userLabel.text = usr;
}

@end
